package com.interceptor;

import com.domain.Employee;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author shkstart
 * @create 2022/3/14-17:55
 */
public class LoginInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
        //获取当前登录的用户
        HttpSession session = req.getSession();
        Employee employee = (Employee) session.getAttribute("EMP_IN_SESSION");
        if (employee == null) {   //没有登录,不放行
            resp.sendRedirect("/login.html");   //回到登录界面
            return false;
        }
        return true;   //已经登录,放行
    }
}
